﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Data;
using System.Data.SqlClient;
using DAL.Entities;

namespace DAL.Entities_DAL
{
    public class LOAI_PHONG_DAL: BaseDAL
    {
        public DataTable Select()
        {
            var sql = @"SELECT * FROM LOAI_PHONG";
            return ExecuteQuery(sql);
        }

        public bool Delete(string id)
        {
            string sql = @"DELETE FROM LOAI_PHONG WHERE MA_LP = '{0}'";
            sql = string.Format(sql, id);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public bool Insert(object obj)
        {
            var o = (LOAI_PHONG)obj;
            string sql = @"set dateformat dmy;INSERT INTO LOAI_PHONG(MA_LP, TEN_LP) VALUES('{0}',N'{1}')";
            sql = string.Format(sql, o.MA_LP, o.TEN_LP);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public bool Update(object obj)
        {
            var o = (LOAI_PHONG)obj;
            string sql = @"set dateformat dmy;UPDATE LOAI_PHONG SET TEN_LP=N'{1}' where MA_LP='{0}'";
            sql = string.Format(sql, o.MA_LP, o.TEN_LP);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public DataTable Select_max()
        {
            var sql = @"SELECT max(MA_LP) as id FROM LOAI_PHONG";
            return ExecuteQuery(sql);
        }

        public string Select_count()
        {
            string sql = @"SELECT count(MA_LP) as id FROM LOAI_PHONG";
            var tb = ExecuteQuery(sql);
            return tb.Rows.Count > 0 ? tb.Rows[0]["id"] + "" : "0";
        }
    }
}
